#ifndef LISTNODE_H_INCLUDED
#define LISTNODE_H_INCLUDED
#include <iostream>
#include "listnode.h"

using namespace std;

struct Listnode {
    Listnode() {
        num = 0;
    }
    Listnode(int data) {
        num = data;
        next = NULL;
    }
    void insert(int x) {
        Listnode *pf = new Listnode(x);
        if (head->next == NULL)
        {
            head->next = pf;
            return;
        }
        Listnode *p = head->next;
        while (x--)
        {
            p = p->next;
        }
        if (p->next == NULL)
        {
            p->next = pf;
            return;
        }
        Listnode *p1 = p->next;
        p->next = pf;
        pf->next = p1;
        return;
    }
    void List_delete(int x)
    {
        if (head->next == NULL)
        {
            cout << "no node" << endl;
            return;
        }
        Listnode *p = head->next;
        Listnode *pf = head;
        while (p != nullptr)
        {
            if (p->num == x)
            {
                pf = p->next;
                return;
            }
            p = p->next;
            pf = pf->next;
        }
        return;
    }
    int List_find(int x)
    {
        if (head->next == NULL)
        {
            cout << "no node" << endl;
            return 0;
        }
        Listnode *p = head->next;
        while (p != NULL)
        {
            if (p->num == x)
            {
                return p->num;
            }
            p = p->next;
        }
        cout << "no data" << endl;
        return 0;
    }
    void List_print()
    {
        if (head->next == NULL)
        {
            cout << "no node" << endl;
            return;
        }
        Listnode *p = head->next;
        while (p != NULL)
        {
            cout << p->num << endl;
            p = p->next;
        }
    }
    int num;
    Listnode *head;
    Listnode *next;
};


#endif // LISTNODE_H_INCLUDED
